<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
</head>

<body>
    <script>
        var info = "<div>hello{{uname}},你多大了？ 我{{age}}岁了</div>";
        var user = {
            uname: "张三",
            age: 12
        };
        var pattern = /{{\s*([a-zA-Z]+)\s*}}/;
        var ret = pattern.exec(info);
        console.log(ret);
        var key = ret[0];
        var val = user[ret[1]];
        var result1 = info.replace(key, val);
        console.log(result1);

        var ret2 = pattern.exec(result1);
        var result2 = result1.replace(ret2[0], user[ret2[1]]);
        console.log(result2);

        // 如果没有匹配到结果就返回null（结束条件）
        var ret3 = pattern.exec(result2);
        console.log(ret3);
    </script>
</body>

</html>